package cn.xuewenbao.edu.service.impl;

import cn.xuewenbao.edu.entity.OneSubject;
import cn.xuewenbao.edu.entity.vo.OneSubjectVo;
import cn.xuewenbao.edu.mapper.OneSubjectMapper;
import cn.xuewenbao.edu.service.OneSubjectService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.common.api.vo.Result;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author mafayu
 * @since 2021-07-08
 */
@Service
public class OneSubjectServiceImpl extends ServiceImpl<OneSubjectMapper, OneSubject> implements OneSubjectService {

    //获取所有一级分类表
    @Override
    public Result<List<OneSubjectVo>> getAllOneSubject() {
        Result<List<OneSubjectVo>> result = new Result<>();
        List<OneSubject> subjectList = baseMapper.selectList(null);
        List<OneSubjectVo> subjectVoList = new ArrayList<>();
        for (OneSubject oneSubject : subjectList) {
            OneSubjectVo subjectVo = new OneSubjectVo();
            BeanUtils.copyProperties(oneSubject, subjectVo);
            subjectVoList.add(subjectVo);
        }
        result.setResult(subjectVoList);
        return result;
    }

}
